package cn.ly.nsfw.user.action;

import java.util.List;

import javax.annotation.Resource;

import cn.ly.nsfw.user.entity.User;
import cn.ly.nsfw.user.service.UserService;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
	@Resource
	private UserService userService;
	private List<User> userlist;
	private User user;
	private String[] selectedRow;
	
	//列表页面,查询出所有数据库当中所有的数据
	/**
	 * 1:返回列表页面对用的listUI.jsp
	 * @return
	 */
	public String listUI(){
		userlist=userService.findObjects();
		return "listUI";
	}
	/**
	 * 2:跳转到新增页面
	 */
	public String addUI(){
		return "addUI";
	}
	/**
	 * 3:保存新增
	 */
	public String add(){
		if(user!=null){
			userService.save(user);
		}
		return "list";
	}
	/**
	 * 4:跳转到编辑页面
	 */
	public String editUI(){
		if(user!=null&&user.getId()!=null){
			userService.findObjectById(user.getId());
		}
		return "editUI";
	}
	/**
	 * 5:保存编辑
	 * @return
	 */
	public String edit(){
		if(user!=null){
			userService.update(user);
		}
		return "list";
	}
	/**
	 * 6:删除，根据id来进行删除用户
	 * @return
	 */
	public String delete(){
		if(user!=null&&user.getId()!=null){
			userService.delete(user.getId());
		}
		return "list"; 
	}
	/**
	 * 7:批量删除用户,删除选中的用户
	 * @return
	 */
	public String deleteSelected(){
		if(selectedRow!=null){
			for(String id:selectedRow){
				userService.delete(id);
			}
		}
		return "list";  
	}
	
	
	
	
	
	public List<User> getUserlist() {
		return userlist;
	}
	public void setUserlist(List<User> userlist) {
		this.userlist = userlist;
	}
	
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	public String[] getSelectedRow() {
		return selectedRow;
	}
	public void setSelectedRow(String[] selectedRow) {
		this.selectedRow = selectedRow;
	}
	
	
}
